const reg = /^\s*([\w$_]+|(async\s*)?(\([^)]*?\)|[^=]+))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;

// 1. function xx() {}
// 2. function () {}
// 3. xx => {}
// 4. (xx) => {}

// 5. async function xx() {}
// 6. async function () {}
// 7. async xx => {}
// 8. async (xx) => {} 

const fn1 = `  function xx(xx) {

}`
const fn2 = `function () {

}`
const fn3 = `   xx => {   }`
const fn4 = `  (xx)   => {}`
const fn5 = `   async    function xx() {}`
const fn6 = `  async   function () {}`
const fn7 = `  async = => {

}`
const fn8 = `async (xx) => {} `


const fn = async  => {
    console.log('a')
}

console.log(reg.test(fn1))
console.log(reg.test(fn2))
console.log(reg.test(fn3))
console.log(reg.test(fn4))
console.log(reg.test(fn5))
console.log(reg.test(fn6))
console.log(reg.test(fn7))
console.log(reg.test(fn8))